/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.ucue.ptc.rest;

import edu.ucue.ptc.gco.mdl.Cliente;
import edu.ucue.ptc.gco.ngc.ClienteManagerLocal;
import edu.ucue.ptc.gco.ngc.UsuarioManagerLocal;
import edu.ucue.ptc.gco.util.AtributoInvalidoException;
import edu.ucue.ptc.gco.util.ClienteValidadorException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.PathParam;

/**
 * REST Web Service
 *
 * @author Valex
 */
@Path("crearCliente/{cedula}/{nombre}/{apellido}/{telefono}/{email}/{user}/{password}/{callback}")
@RequestScoped
public class CrearClienteResource {

    @Context
    private UriInfo context;

    @Inject
    private UsuarioManagerLocal UsuarioManager;
    @Inject
    private ClienteManagerLocal ClienteManager;
    /**
     * Creates a new instance of CrearClienteResource
     */
    public CrearClienteResource() {
    }

    /**
     * Retrieves representation of an instance of edu.ucue.ptc.rest.CrearClienteResource
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("application/json")
    public String getJson(@PathParam("cedula") String cedula,@PathParam("nombre") String nombre, 
    @PathParam("apellido") String apellido,@PathParam("telefono") String telefono,@PathParam("email") String email,  
    @PathParam("user") String user, @PathParam("password") String pass, @PathParam("callback") String callback) {
        try {
            //TODO return proper representation object
            Cliente cliente=new Cliente();
            cliente.setCedulaRuc(cedula);
            cliente.setNombres(nombre);
            cliente.setApellidos(apellido);
            cliente.setTelefono(telefono);
            cliente.setEmail(email);
            ClienteManager.crear(cliente);
             return callback+"({\"callback\":\"" + callback + "\",\"respuesta\":\"" + "Ingreso Exitoso" + "\"})";
        } catch (ClienteValidadorException ex) {
             return callback+"({\"callback\":\"" + callback + "\",\"errormsg\":\"" + "ClienteValidadorExcepton" + "\"})";
        } catch (AtributoInvalidoException ex) {
             return callback+"({\"callback\":\"" + callback + "\",\"errormsg\":\"" + "AtributoInvalidoException" + "\"})";
        }
    }

    /**
     * PUT method for updating or creating an instance of CrearClienteResource
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("application/json")
    public void putJson(String content) {
    }
}
